package com.example.mine


import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.mine.databinding.ActivityMemberBinding

@Route(path = "/mine/MemberActivity")
class MemberActivity : BaseMvvmActivity<ActivityMemberBinding>() {
    override fun getLayoutId(): Int = R.layout.activity_member
    var grade = "无"
    override fun initView() {
        super.initView()
        mDataBinding.gold.setOnClickListener {
            updateMemberStyle("黄金会员")
        }
        mDataBinding.platinum.setOnClickListener {
            updateMemberStyle("铂金会员")
        }
        mDataBinding.diamond.setOnClickListener {
            updateMemberStyle("钻石会员")
        }
        mDataBinding.up.setOnClickListener {
            updateMemberStyle(grade)

        }
        // 初始化默认选中状态
        resetMemberStyles()
    }

    private fun updateMemberStyle(type: String) {
        // 重置所有按钮样式
        resetMemberStyles()

        // 根据选中的类型设置对应样式
        when (type) {
            "无" -> {
                grade = "黄金会员"
                mDataBinding.gold.setBackgroundResource(R.drawable.gold_member_selected_bg)
                mDataBinding.gold.setTextColor(getColor(R.color.white))
                mDataBinding.discount.text = "商家9.5折"
                mDataBinding.points.text = "10积分抵1元"
                mDataBinding.coupon.text = "10元停车券"
                mDataBinding.member.text = "黄金会员"
            }
            "黄金会员" -> {
                mDataBinding.gold.setBackgroundResource(R.drawable.gold_member_selected_bg)
                mDataBinding.gold.setTextColor(getColor(R.color.white))
                mDataBinding.discount.text = "商家9.5折"
                mDataBinding.points.text = "10积分抵1元"
                mDataBinding.coupon.text = "10元停车券"
                mDataBinding.member.text = "黄金会员"
                grade = "铂金会员"

            }
            "铂金会员" -> {
                mDataBinding.platinum.setBackgroundResource(R.drawable.gold_member_selected_bg)
                mDataBinding.platinum.setTextColor(getColor(R.color.white))
                mDataBinding.discount.text = "商家8.0折"
                mDataBinding.points.text = "10积分抵5元"
                mDataBinding.coupon.text = "30元停车券"
                mDataBinding.member.text = "铂金会员"
                grade = "钻石会员"
            }
            "钻石会员" -> {
                mDataBinding.diamond.setBackgroundResource(R.drawable.gold_member_selected_bg)
                mDataBinding.diamond.setTextColor(getColor(R.color.white))
                mDataBinding.discount.text = "商家6.0折"
                mDataBinding.points.text = "10积分抵10元"
                mDataBinding.coupon.text = "50元停车券"
                mDataBinding.member.text = "钻石会员"
            }
        }
    }

    private fun resetMemberStyles() {
        // 重置为默认未选中样式
        mDataBinding.gold.setBackgroundResource(R.drawable.member_unselected_bg)
        mDataBinding.gold.setTextColor(getColor(R.color.gray_666))

        mDataBinding.platinum.setBackgroundResource(R.drawable.member_unselected_bg)
        mDataBinding.platinum.setTextColor(getColor(R.color.gray_666))

        mDataBinding.diamond.setBackgroundResource(R.drawable.member_unselected_bg)
        mDataBinding.diamond.setTextColor(getColor(R.color.gray_666))
    }

}
